import { BaseService } from '@app/db/base/base.service';
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { JsonContains, Repository } from 'typeorm';
import { Lang } from '../entities/Lang';

@Injectable()
export class LangService extends BaseService<Lang>{
    constructor(
        @InjectRepository(Lang, 'common') protected repository:Repository<Lang>
    ) {
        super()
        this.primaryKey = 'id'
    }

    async queryCodeByLang(lang:string, locale:string) {
        locale = locale.toLocaleUpperCase()
        const res = await this.findOne({values : JsonContains({[locale] : lang})}, {code : true})
        return res ? res.code : lang
    }
}
